<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@include file="/common/common.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<script type='text/javascript' src='${pageContext.request.contextPath}/dwr/interface/permissionService.js'></script>
	<script type='text/javascript' src='${pageContext.request.contextPath}/dwr/engine.js'></script>
	<script type='text/javascript' src='${pageContext.request.contextPath}/dwr/util.js'></script>
	<script type="text/javascript">
		function addOrModifyPermission(field) {
			//if checked addormodiy item ,or delete
			var res = field.attributes['resource'].nodeValue;
			//alert(res);
			if(field.checked) {
				//alert(field.resource);
				$(res+"_per").checked = true;
				permissionService.addPersonneltorulelink(
					res,
					"${personnel.staffcode}"
				);
			} else {
				$(res+"_per").checked = false;
				permissionService.removePersonneltorulelink(
					res,
					"${personnel.staffcode}"
				);
			}
		}
	
		//初始化页面
		function initTable() {
			permissionService.findPersonneltoruleByStaffcode(
				"${personnel.staffcode}",
				function(data){
					for(var i=0;i<data.length;i++){
						var resource = data[i][0];
						$(resource+"_per").checked = true;
					}
				}
			);
		}
	</script>
	
	<title>	
		为帐号${personnel.loginname}授权
	</title>
	</head>
	<body bgcolor="#ccddee" link="#000066" vlink="#0066FF" alink="#99FF00" onload="initTable()">
		<center>
			<table cellspacing="0" border="0" cellpadding="0" style="width:100%;">
				<tr>
			        <td align="center">选择</td>
			        <td align="center">角色名称</td>
			        <td align="center">选择</td>
			        <td align="center">角色名称</td>
			        <td align="center">选择</td>
			        <td align="center">角色名称</td>
      			</tr>
      			<tr>
      			<s:iterator value="rulelist"  status="rowstatus" var="rule">
      				<td  align="center">
      					<input type="checkbox" id="<s:property value="ruleno"/>_per" onclick="addOrModifyPermission(this)" resource="<s:property value="ruleno"/>" >
      				</td>
      				<td  align="center"><s:property value="rulename"/></td>
      				<s:if test="#rowstatus.count%3 == 0"></tr><tr></s:if>
      			</s:iterator>
      		</table>
		</center>

	</body>
</html>
